package com.icw.resource.inner.module.api;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.icw.configuration.ConstSettings;
import com.icw.decoupling.defi.tool.BinaryDataManager;
import com.icw.decoupling.impl.module.RestfulApiImpl;
import com.icw.resource.inner.entity.IcwFileContent;
import com.icw.utility.BeanCtxUtils;
import com.icw.utility.IcwUtils;

public class IcwFileContentRestfulApi extends RestfulApiImpl<IcwFileContent> {

	@Override
	public void getone(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		if (request.getParameter("download") != null) {
			IcwUtils.copyStreamAndClose(BeanCtxUtils.getBeanByType(BinaryDataManager.class).read((String) params.get("id")), response.getOutputStream());
		} else {
			data.put("data", BeanCtxUtils.getBeanByType(BinaryDataManager.class).src((String) params.get("id")));
		}
	}

	@Override
	public void delete(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		throw ConstSettings.NOT_ALLOW;
	}

	@Override
	public void getlist(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		throw ConstSettings.NOT_ALLOW;
	}

	@Override
	public void post(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		throw ConstSettings.NOT_ALLOW;
	}

	@Override
	public void patch(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		throw ConstSettings.NOT_ALLOW;
	}

	@Override
	public void getexcel(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		throw ConstSettings.NOT_ALLOW;
	}

	@Override
	public void exists(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		throw ConstSettings.NOT_ALLOW;
	}
}
